package com.example.myapplication.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.myapplication.R;
import com.example.myapplication.utils.SplitHelper;
import com.example.myapplication.utils.VcsSplit;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView mTextView;
    private TextView mVcsTextView;
    private VcsSplit mWithoutEtSplit;
    private EditText mEditText;
    private SplitHelper mVcsSplitHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EditText vcsEditText = findViewById(R.id.vcs_edit_text);
        mVcsTextView = findViewById(R.id.vcs_text);
        mEditText = findViewById(R.id.edit_text);
        mTextView = findViewById(R.id.without_et_text);
        findViewById(R.id.vcs_format_button).setOnClickListener(this);
        findViewById(R.id.vcs_original_button).setOnClickListener(this);
        findViewById(R.id.without_et_format_button).setOnClickListener(this);
        //使用EditText
        mVcsSplitHelper = new SplitHelper.SplitBuilder()
                .setSplit(new VcsSplit())//设置隔断模板
                .setEditText(vcsEditText)
                .setEnable(true)//是否可用 默认true
                .build();

        //不使用EditText
        mWithoutEtSplit = new VcsSplit();
    }

    @Override
    public void onClick(View view) {
        String result = "result:";
        if (view.getId() == R.id.vcs_format_button) {//使用EditText 获得隔断后的号码
            mVcsTextView.setText(result + mVcsSplitHelper.getFormatNumber());
        } else if (view.getId() == R.id.vcs_original_button) {//使用EditText 获得原始号码
            mVcsTextView.setText(result + mVcsSplitHelper.getOriginalText());
        } else if (view.getId() == R.id.without_et_format_button) {//不使用EditText获得隔断后的号码
            mTextView.setText(result + mWithoutEtSplit.getFormatNumber(mEditText.getText().toString()));
        }
    }
}